<template>
    <div class="conditionsApprove">
        <div style="background:white;padding:20px">
            <Row>
                <Col span="4" class="div-basic">
                    <h2>申请信息</h2>
                    <div>
                        <h3 style="font-weight: normal;" class="mt10">金融产品: {{this.orderInfo.productName}}</h3>
                        <ul class="over">
                            <li class="div-span-class">申请编号: {{this.orderInfo.applyNo}}</li>
                            <li class="div-span-class">客户姓名: {{this.orderInfo.custName}}</li>
                            <li class="div-span-class">合作商: {{this.orderInfo.channelName}}</li>
                            <li class="div-span-class">业务类型: {{businessTypeStr}}</li>
                            <li class="div-span-class">车辆类型: {{carTypeStr}}</li>
                            <li class="div-span-class">车辆属性: {{carNatureStr}}</li>
                            <li class="div-span-class">运营方式: {{operateWayStr}}</li>
                            <li class="div-span-class">挂靠方式: {{affiliatedWayStr}}</li>
                            <li class="div-span-class">购车目的: {{carPurposeStr}}</li>
                        </ul>
                    </div>
                </Col>
                <Col span="10">
                    <Card style="margin-left: 40px;min-height: 280px;" class="mb10">
                        <div>
                            <car-loan
                                :carCostDetails="carCostDetails"
                                v-if="isAdditional=='0'||(isAdditional=='1'&&isSubProduct=='1')"
                            ></car-loan>
                            <carAdditional-loan
                                v-if="isAdditional=='1'&&isSubProduct=='0'"
                                :carCostDetails="carCostDetails"
                            ></carAdditional-loan>
                        </div>
                    </Card>
                    <div v-if="isAdditional=='1'&&isSubProduct=='1'">
                        <Card style="margin-left: 40px;">
                            <additional-loan :addCostDetails="addCostDetails"></additional-loan>
                        </Card>
                    </div>
                </Col>
                <Col span="9" offset="1">
                    <loan-info
                        :isAdditional="isAdditional"
                        :carDiscountOption="carDiscountOption"
                        :additionalDiscountOption="additionalDiscountOption"
                        :carCostDetails="carCostDetails"
                        :addCostDetails="addCostDetails"
                        :isSubProduct="isSubProduct"
                    ></loan-info>
                    <total-info :totalInfoData="totalInfoData"></total-info>
                </Col>
            </Row>
            <div class="submit mt10" style="text-align: center;">
                <Button @click="cancel">放弃申请</Button>
                <Button type="primary" @click="agree">同意</Button>
                <Button type="primary" @click="turnBack">返回</Button>
            </div>
        </div>
    </div>
</template>
<script>
    import {
        getConditionApprove
    } from "_p/afs-apply/api/apply-report/conditions-approve/conditionsApprove.js"
    import {getByTypes} from "_p/basic/api/admin/datadic";
    import basicinfo from "_p/afs-apply/pages/apply-report/common/apply-basic-info.vue";
    import "../../../assets/css/base.css";
    import CarLoan from "./car-loan/carLoan";
    import AdditionalLoan from "./additional-loan/additionalLoan"
    import CarAdditionalLoan from "./carAdditional-loan/carAdditionalLoan"
    import LoanInfo from "./loan-info/loanInfo"
    import TotalInfo from "./total-info/totalInfo"
    import {deepClone} from "@/libs/utils/ObjectClone";
    import {sendConditionApprovalMessage} from "../../../api/apply-report/conditions-approve/conditionsApprove";
    import * as utils from '_p/afs-apply/assets/js/utils.js'

    export default {
        name: "conditionsApprove",
        data() {
            return {
                orderInfo: {},
                applyNo: '',
                // 初始化查询车贷变量
                carCostDetails: {},
                // 初始化查询附加贷变量
                addCostDetails: {},
                totalInfoData: {},
                isAdditional: "0",//附加贷
                isSubProduct: "1",//是否为同一个产品
                carDiscountOption: "0",//车贷贴息方式
                additionalDiscountOption: "0",//附加贷贴息方式
                dataDic: {
                    businessType: [],
                    operateWay: [],
                    affiliatedWay: [],
                    carPurpose: [],
                    carType: [],
                    carNature: [],
                },
            }
        },
        components: {
            CarLoan,
            AdditionalLoan,
            LoanInfo,
            TotalInfo,
            basicinfo,
            CarAdditionalLoan
        },
        mounted() {
            let applyNo = this.afs.getPageParams(this);
            this.initDataDic();
            if (applyNo) {
                this.applyNo = this.afs.getPageParams(this).applyNo;
                this.getConditionApprove(applyNo.applyNo);
            }
        },
        computed: {
            carNatureStr() {
                return utils.setDataDictVal(this.dataDic.carNature, this.orderInfo.carNature)
            },
            carTypeStr() {
                return utils.setDataDictVal(this.dataDic.carType, this.orderInfo.carType);
            },
            businessTypeStr() {
                return utils.setDataDictVal(this.dataDic.businessType, this.orderInfo.businessType);
            },
            operateWayStr() {
                return utils.setDataDictVal(this.dataDic.operateWay, this.orderInfo.operateWay);
            },
            affiliatedWayStr() {
                return utils.setDataDictVal(this.dataDic.affiliatedWay, this.orderInfo.affiliatedWay);
            },
            carPurposeStr() {
                return utils.setDataDictVal(this.dataDic.carPurpose, this.orderInfo.carPurpose);
            },
        },
        methods: {
            //取消附条件申请,将订单状态改为取消，通知信审
            cancel() {
                let params = {
                    applyNo: this.applyNo,
                    result: false,
                }
                this.$Modal.confirm({
                    title: "放弃申请",
                    content: "客户的申请将被取消，是否仍要取消 ?",
                    onOk: () => {
                        sendConditionApprovalMessage(params).then(res => {
                            if (res.code === '0000') {
                                this.afs.closeTab(this);
                            }
                        });
                    }
                });
            },
            //同意附条件申请,将订单状态改为核准，通知信审
            agree() {
                let params = {
                    applyNo: this.applyNo,
                    result: true,
                }
                sendConditionApprovalMessage(params).then(res => {
                    if (res.code === '0000') {
                        this.$Message.success("同意附条件申请")
                        this.afs.closeTab(this);
                    }
                });
            },
            //返回,关闭当前tab页
            turnBack() {
                this.afs.closeTab(this);
            },
            // 获取附条件核准信息
            getConditionApprove(applyno) {
                let param = {
                    applyNo: applyno,
                }
                getConditionApprove(param).then((res) => {
                    if (res.code == "0000") {
                        this.orderInfo = Object.assign({}, this.orderInfo, res.data.orderInfo);
                        this.isAdditional = res.data.isAdditional;
                        this.isSubProduct = res.data.isSubProduct;
                        // 当dom渲染完毕
                        this.$nextTick(function () {
                            // 附加贷产品
                            if (res.data.addCostDetails && Object.keys(res.data.addCostDetails).length > 0) {
                                this.addCostDetails = res.data.addCostDetails;
                                this.additionalDiscountOption = res.data.addCostDetails.discountOption;
                                console.log(this.additionalDiscountOption, "additionalDiscountOption")
                            }
                            // 主产品
                            if (res.data.carCostDetails) {
                                this.carCostDetails = res.data.carCostDetails;
                                this.carDiscountOption = res.data.carCostDetails.discountOption;
                                console.log(this.carDiscountOption, "carDiscountOption")
                            }
                            // 总合计信息
                            if (res.data.totalInfo) {
                                this.totalInfoData = res.data.totalInfo;
                            }
                        })
                    }
                })
            },
            initDataDic() {
                //数据字典
                let arr = ["operateWay", "affiliatedWay", "carPurpose", "businessType", "carType", "carNature"];
                getByTypes(arr).then(res => {
                    if (res.code === "0000") {
                        console.log(this.dataDic, "this.dataDic")
                        this.dataDic = deepClone(res.data);
                    }
                });
            }
        }
    }
</script>
<style scoped>
    .div-basic ul > li {
        margin-top: 10px;
        margin-left: 20px;
    }

    .div-basic h3 {
        font-size: 12px;
        margin-left: 20px;
    }

    .submit button {
        width: 80px;
        height: 30px;
        margin-right: 10px;
    }

    .submit > button:first-child {
        background-color: rgb(193, 193, 193);
        color: white;
    }

    .submit > button:first-child:active {
        border-color: rgb(193, 193, 193);
    }

    .submit > button:first-child:focus {
        box-shadow: none;
    }

    .submit > button:first-child:hover {
        color: white;
        border-color: rgb(193, 193, 193);
    }
</style>
